package ;

/**
 * ...
 * @author Tony Polinelli
 */

#if macro
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Tools;
#end

class RttiMacro
{

   @:macro public static function applyRtti():Expr
   {

       haxe.macro.Context.onGenerate(function (types) {

           for ( t in types )
           {
               switch( t )
               {
                   case TInst(c, _):
                       if (c.get().name == "Main") {
							
                           var rttiData = c.get();
                           trace(rttiData.meta.get()); // [{ params => [], name => before }]
                           // add meta rtti to Main
                           rttiData.meta.add( "rtti", [], rttiData.pos );
                           // it seems to work
                           trace(rttiData.meta.get()); // [{ params => [], name => rtti }, { params => [], name => before }]
                       }

                   default:
               }
           }
       });
       var ret = EConst(CType("Void"));
		
	   trace(Context.parse("foo = 5", Context.currentPos()));

	   var r = EBinop(OpAssign, { expr: EConst(CIdent("foo")), pos:Context.currentPos() }, { expr:EConst(CInt("5")), pos:Context.currentPos() } );
	   
		Context.getType("Main").
	   trace(r);
	   
       return {expr: ret, pos:haxe.macro.Context.currentPos()};
   }
}
